package magicboard.model
{
  import flash.geom.Point;
  
  /**
  * Vector is defined by its x and y components.
  */
  public class Vector
  {
    // --------------------------------------------------------------------------------------------
    public function Vector(x1:Number, y1:Number)
    {
      _x = x1;
      _y = y1;
    }

    // --------------------------------------------------------------------------------------------
    public function get x():Number{return _x; }
    public function get y():Number{return _y; }
    
		// --------------------------------------------------------------------------------------------
		/** Get length (norm) of the vector */
		public function getLength():Number{
			return Math.sqrt(getLength2());
		}

		// --------------------------------------------------------------------------------------------
		/** Get length^2 of the vector */
		public function getLength2():Number{
			return _x*_x + _y*_y;
		}

    // --------------------------------------------------------------------------------------------
    /** dot product (iloczyn skalarny)*/
    static public function dot(v1:Vector, v2:Vector):Number{
      return v1.x * v2.x + v1.y * v2.y; 
    }

    // --------------------------------------------------------------------------------------------
    /** create vector defined by 2 points */
    static public function points2Vector(p1:Point, p2:Point):Vector{
      return new Vector(p2.x-p1.x, p2.y-p1.y); 
    }

    // --------------------------------------------------------------------------------------------
    // Private members
    private var _x:Number;
    private var _y:Number;
  }
}